package com.enba.boot.security.jwt;

import com.enba.boot.core.base.Result;
import com.enba.boot.security.enums.AuthStatusEnum;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

/** 未登录时访问权限接口时触发 */
public class DefaultJwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
  @Override
  public void commence(
      HttpServletRequest request, HttpServletResponse response, AuthenticationException e)
      throws IOException {
    Result.render(
        response,
        Result.err(
            AuthStatusEnum.AUTHENTICATION_ENTRY_POINT.getCode(),
            AuthStatusEnum.AUTHENTICATION_ENTRY_POINT.getMsg()));
  }
}
